package com.yyi.springcloud.controller;


import com.yyi.springcloud.common.JedisClientSingle;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//保存页面数据的Controller
@Controller
@RequestMapping("/mysqlapi/pageData")

public class Mysql_PageDataController {
	@Resource
	private JedisClientSingle jedisClientSingle;
	@ResponseBody
    //将页面中的div曲线数据保存在redis中
	@RequestMapping(value ="/putDivCruveData", method = { RequestMethod.GET, RequestMethod.POST })
	//http://localhost:8080/bxxs/api/pageData/putDivCruveData?primaryKey=2017-11-1611:17:211&cruveData=demo
	public String putDivCruveData(HttpServletRequest request, Model model, HttpServletResponse response) {
		String primaryKey = request.getParameter("primaryKey");
		String cruveData = request.getParameter("cruveData");
		// 选择redis的第1个数据库
		jedisClientSingle.selectDbHSet(1, "CruveData", primaryKey+"div", cruveData);
		return "success";
	}
	@ResponseBody
	@RequestMapping(value ="/getDivCruveData", method = { RequestMethod.GET, RequestMethod.POST })
	//http://localhost:8080/bxxs/api/pageData/getDivCruveData?primaryKey=2017-11-1611:17:211
	public String getDivCruveData(HttpServletRequest request, Model model, HttpServletResponse response) {
		String primaryKey = request.getParameter("primaryKey");
		// 选择redis的第1个数据库
		String result = jedisClientSingle.selectDbHGet(1, "CruveData", primaryKey+"div");
		return result;
	}


	//将页面中的canvas曲线数据保存在redis中
    @ResponseBody
	@RequestMapping(value ="/putCanvasCruveData", method = { RequestMethod.GET, RequestMethod.POST })
	//http://localhost:8080/bxxs/api/pageData/putCanvasCruveData?primaryKey=2017-11-1611:17:211&cruveData=demo
	public String putCanvasCruveData(HttpServletRequest request, Model model, HttpServletResponse response) {
		String primaryKey = request.getParameter("primaryKey");
		String cruveData = request.getParameter("cruveData");
		// 选择redis的第1个数据库
		jedisClientSingle.selectDbHSet(1, "CruveData", primaryKey+"canvas", cruveData);
		return "success";
	}

	@ResponseBody
	@RequestMapping(value ="/getCanvasCruveData", method = { RequestMethod.GET, RequestMethod.POST })
	//http://localhost:8080/bxxs/api/pageData/getCanvasCruveData?primaryKey=2017-11-1611:17:211
	public String getCanvasCruveData(HttpServletRequest request, Model model, HttpServletResponse response) {
		String primaryKey = request.getParameter("primaryKey");
		// 选择redis的第1个数据库
		String result = jedisClientSingle.selectDbHGet(1, "CruveData", primaryKey+"canvas");
		return result;
	}



	//将左侧页面中的传感器哦信息保存在redis中
	@ResponseBody
	@RequestMapping(value ="/putLeftSensorData", method = { RequestMethod.GET, RequestMethod.POST })
	//http://localhost:8080/bxxs/api/pageData/putLeftSensorData?primaryKey=2017-11-1611:17:211&cruveData=demo
	public String putLeftSensorData(HttpServletRequest request, Model model, HttpServletResponse response) {
		String primaryKey = request.getParameter("primaryKey");
		String leftSensorData = request.getParameter("cruveData");
		// 选择redis的第1个数据库
		jedisClientSingle.selectDbHSet(1, "leftSensorData", primaryKey+"sensorData", leftSensorData);
		return "success";
	}


	@ResponseBody
	@RequestMapping(value ="/getLeftSensorData", method = { RequestMethod.GET, RequestMethod.POST })
	//http://localhost:8080/bxxs/api/pageData/getLeftSensorData?primaryKey=2017-11-1611:17:211
	public String getLeftSensorData(HttpServletRequest request, Model model, HttpServletResponse response) {
		String primaryKey = request.getParameter("primaryKey");
		// 选择redis的第1个数据库
		String result = jedisClientSingle.selectDbHGet(1, "leftSensorData", primaryKey+"sensorData");
		return result;
	}





}
